package com.gpy.hospital.cms.controller;

import com.github.pagehelper.PageInfo;
import com.gpy.hospital.cms.pojo.Keshi;
import com.gpy.hospital.cms.service.IKeShiService;
import com.gpy.hospital.common.ServerResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @Author
 * @Date 2020/2/27 19:26
 * @Desc
 **/
@Controller
public class KeShiController {

    @Autowired
    private IKeShiService keShiService;


    @GetMapping("/cms/keshi/page")
    public String keshiPage() {
        return "/cms/keshiList";
    }


    @GetMapping("/cms/keshi/list")
    @ResponseBody
    public ServerResponse keShiList(
            @RequestParam(value = "page", defaultValue = "1") Integer pageNum,
            @RequestParam(value = "limit", defaultValue = "10") Integer pageSize,
            @RequestParam(value = "name", required = false) String name){
        PageInfo<Keshi> pageInfo = keShiService.get(pageNum, pageSize, name);
        return ServerResponse.createBySuccess("查询成功！", pageInfo.getList(), pageInfo.getTotal());
    }

    @GetMapping("/cms/keshi/editPage")
    public String keshiEdit(@RequestParam("keshiId") Integer keshiId, Model model) {
        Keshi keshi = keShiService.getById(keshiId);
        model.addAttribute("keshi", keshi);
        return "/cms/keshiEditPage";
    }


    @PostMapping("/cms/keshi/save")
    @ResponseBody
    public ServerResponse keshiSave(Keshi keshi) {
        return keShiService.save(keshi);

    }


    @GetMapping("/cms/keshi/delete")
    @ResponseBody
    public ServerResponse delete(@RequestParam("kehsiId") Integer keshiId){
        return keShiService.delete(keshiId);
    }


    @GetMapping("/cms/keshi/add")
    public String keshiAdd() {
        return "/cms/keshiAdd";
    }


    @GetMapping("/keshi/detail")
    public String keshiDetail(@RequestParam("keshiId") Integer keshiId, Model model){
        Keshi byId = keShiService.getById(keshiId);
        model.addAttribute("keshiDetail", byId);
        return "/reception/keshiDetail";
    }

    @GetMapping("/ke/shi/all")
    public String zhuanJiaAllPage(Model model) {
        List<Keshi> doctors =  keShiService.getAllByStatus();
        model.addAttribute("doctors", doctors);
        return "/reception/keShiList";
    }

}
